<#include "admin/include/inside_header.ftl" >
<link rel="stylesheet" href="${baseUrl}public/static/ztree/css/zTreeStyle/zTreeStyle.css">
<body>
  <@t.container title="添加资源" back="true" icon="cubes" >
				<form class="form-horizontal" id="add_form" method="post" role="form">
					<#if bean??>
        				<input type="hidden" id="id" name="id" value="${bean.id}"/>	
					</#if>
					<@t.text title="资源名称" id="text" value="${bean.text!''}" />    
					<@t.select title="资源类型" id="type" datas={"1":"菜单", "0":"功能"}  defaultValue="${bean.type}"> </@t.select>            				  
                	<@t.treeSelect title="父节点" id="pId" value="${bean.pId!'0'}"></@t.treeSelect>
                	<@t.text title="URL" id="url" value="${bean.url!''}" />
                	<@t.text title="顺序" id="seq" value="${bean.seq!'1'}" help="智能输入数字，数字越大排序越靠后~" />
					<@t.submitBtn/>
                </form>
</@t.container>
<#include  "admin/include/footer.ftl">
<script type="text/javascript" src="${baseUrl}public/static/ztree/js/jquery.ztree.all-3.5.min.js"></script>
 <script type="text/javascript">
     $(function(){
		//提交表单
       	  $('#add_form').validator({
        		theme: 'yellow_right_effect',  //设置theme
        		stopOnError: true, //
        		showOk:false,
        	    fields: {
        	        "text": {
        	            rule: "required;",
        	            ok: "",
        	            tip:"请填写资源名称",
        	            msg: {
        	            	required: "资源名称不可以为空!",
        	            }
        	        }
        	    }
        	});
		  $('#add_form').on('valid.form', function(e, form){
		  	   //成功之后刷新gd，关闭自己
			   var data=$(this).serialize();
			    var this_obj=$('#submit_btn');
				//提交表单
				this_obj.addClass('disabled');
				this_obj.html('提交中...');
               $ .axsf('admin/resource/add',data,function(d){
			   		if(d){
                         if(d.code==200){
							window.location.href="admin/resource/index";
                         }else{
						 	alert(d.message);
						 }
                	}
					 this_obj.removeClass("disabled");
             		 this_obj.html('保存');
			   });
        });
	        
		   $ .fn.zTree.init($("#pId_tree"), setting, zNodes);
		   $('#pId_name').click(function(){
				if($('#pId_tree_wrap').css('display')=='none'){
					$('#pId_tree_wrap').css('display','block');
				}else{
					$('#pId_tree_wrap').css('display','none');
				}
			});
			//修改模拟
			setTreeValu('pId');
});
    	 function setTreeValu(id){
			var id=$('#'+id).val();
			var treeObj = $ .fn.zTree.getZTreeObj("pId_tree");
			var nodes = treeObj.getNodesByParam("id", id, null);
			if(nodes.length==1){
				$('#pId_select_text').html(nodes[0].text);	
				treeObj.selectNode(nodes[0]);
			}
	     }
		function zTreeOnClick(event, treeId, treeNode) {
			   $('#pId').val(treeNode.id);
			   $('#pId_select_text').html(treeNode.text);
			   $('#pId_tree_wrap').css('display','none');
		};
		var setting = {
			callback: {
				onClick: zTreeOnClick
			},
			data: {
				key: {
					name: "text",
					url: "xUrl"
				}
			}
		};
		var zNodes =${res_tree!"[]"};
	</script>
   </body>
   </html> 
    